class ScorePanel {
    score: number = 0;
    level: number = 1;

    scoreElement: HTMLElement;
    levelElement: HTMLElement;

    maxLevel:number;

    constructor(maxLevel:number = 10) {
        this.scoreElement = document.getElementById('score')!;
        this.levelElement = document.getElementById('level')!;
        this.maxLevel = maxLevel;
    }

    addScore() {
        this.score++;
        this.scoreElement.innerHTML = `${this.score}`;

        if(this.score % 10 == 0){
            this.levelUp();
        }
    }

    //升级
    levelUp() {
        if (this.level < this.maxLevel) {
            this.level++;
            this.levelElement.innerHTML = `${this.level}`;
        }

    }
}

export default ScorePanel;


// let scorePanel = new ScorePanel();
// scorePanel.addScore();
// scorePanel.addScore();
// scorePanel.addScore();
// scorePanel.levelUp();